package com.example.utils;

import lombok.Data;

import java.util.Date;

@Data
public class ExceptionResult {
    private int status;
    private String message;
    private Date timestamp;
    private Object data;
    public ExceptionResult(ExceptionEnum exceptionEnum){
        this.status = exceptionEnum.getCode();
        this.message = exceptionEnum.getMsg();
        this.timestamp = new Date();
    }
    public ExceptionResult(int status, String message, Object data) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.timestamp = new Date();
    }

    public static ExceptionResult success(){
        return new ExceptionResult(200,"成功",null);
    }
    public static ExceptionResult success(Object data){
        return new ExceptionResult(200,"成功",data);
    }
    public static ExceptionResult error(int status, String message){return new ExceptionResult(status,message,null);}
    public static ExceptionResult error(){
        return new ExceptionResult(500,"系统错误",null);
    }
}
